// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';
import ElementUI from 'element-ui';
import VueResource from 'vue-resource';
// import axios from '@/components/common/http';
import '../static/css/#a88e59/index.css';
import webconfig from '@/components/common/WebSet';

// Vue.config.productionTip = false;

// Vue.prototype.$http = axios;

/* eslint-disable no-new */
Vue.prototype.WEB_CONFIG = webconfig;

Vue.use(VueResource);
Vue.http.options.emulateJSON = true;
// Vue.http.options.emulateHTTP = true;

// HTTP相关
// Vue.http.options.crossOrigin = true;
// Vue.http.options.xhr = {withCredentials: true};

// Vue.http.interceptors.push((request, next) => {
//
//   // modify request ...
//
//   // stop and return response
//      next(request.respondWith(body, {
//          status: 404,
//          statusText: 'Not found'
//      }));
// });

Vue.http.interceptors.push((request, next) => {
    // if (localStorage.admin_token) {
    //     console.log('localStorage.admin_token=', localStorage.admin_token);
    //     request.headers['token'] = localStorage.admin_token;
    //     request.headers['Authorization'] = 'Bearer: ' + localStorage.admin_token;
    //     // request.headers.set('token', localStorage.admin_token);
    //     // request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
    //     // request.headers.set('X-CSRF-TOKEN', localStorage.getItem('admin-token'));
    // }
    // console.log('request===', request);
    // request.method = 'POST';
    next((response) => {
        console.log('Vue.http.interceptors.push response===', response);
        if (response.body && response.body.status && response.body.status === 401) {
            localStorage.claer;
            window.location.href = '/admin/default/login';
            // window.location.href = '/login';
        }
        // if (response.status === 401 || response.status === 0) {
        //     console.log('response.status===', response.status);
        //     // window.location.href = '/admin/default/login';
        // }
        return response;
    });
});

Vue.use(ElementUI);
new Vue({
    el: '#app',
    router,
    // template: '<App/>',
    // components: {
    //     App
    // }
    render: h => h(App)
});
